package com.xt.stock.project.common.basic;

import com.xt.stock.project.common.constant.XtCodeConstant;
import lombok.Data;

/**
 * 全局返回
 */
@Data
public class GlobalResult<T> {
    //状态码
    private Integer code;
    //返回信息
    private String msg;
    //返回数据
    private T data;

    public static GlobalResult success() {
        GlobalResult globalResult = new GlobalResult();
        globalResult.setCode(XtCodeConstant.TRUE_RETURN);
        return globalResult;
    }

    public static GlobalResult success(Integer code,String msg) {
        GlobalResult globalResult = new GlobalResult();
        globalResult.setCode(null == code?XtCodeConstant.TRUE_RETURN:code);
        globalResult.setMsg(msg);
        return globalResult;
    }

    public static GlobalResult success(Integer code,String msg,Object data) {
        GlobalResult globalResult = new GlobalResult();
        globalResult.setCode(null == code?XtCodeConstant.TRUE_RETURN:code);
        globalResult.setMsg(msg);
        globalResult.setData(data);
        return globalResult;
    }

    public static GlobalResult fail(Integer code,String msg) {
        GlobalResult globalResult = new GlobalResult();
        globalResult.setCode(code);
        globalResult.setMsg(msg);
        return globalResult;
    }

    public static GlobalResult fail(Integer code,String msg,Object data) {
        GlobalResult globalResult = new GlobalResult();
        globalResult.setCode(code);
        globalResult.setMsg(msg);
        globalResult.setData(data);
        return globalResult;
    }

}
